package xyf.p03.hash;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: M1621_FindSwapValues
 * Description:
 * Author: xyf
 * Date: 9/18/22 8:55 PM
 * Version: 1.0
 **/
public class M1621_FindSwapValues
{
    public int[] findSwapValues(int[] array1, int[] array2)
    {
        int sum1 = 0;
        int sum2 = 0;
        Map<Integer, Integer> arrMap2 = new HashMap<>();

        for (int i = 0; i < array1.length; i++)
        {
            sum1 += array1[i];
        }

        for (int i = 0; i < array2.length; i++)
        {
            sum2 += array2[i];
            arrMap2.put(array2[i], i);
        }


        int gap = sum1 - sum2;
        if (gap % 2 != 0)
        {
            return new int[0];
        }
        for (int i = 0; i < array1.length; i++)
        {
            Integer num2 = arrMap2.get(array1[i] - gap / 2);
            if (num2 == null)
            {
                continue;
            }
            int[] res = new int[2];
            res[0] = array1[i];
            res[1] = array1[i] - gap / 2;
            return res;
        }
        return new int[0];
    }
}